using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FanDongping.Stock
{
    public partial class FmEditStockInfo : Form
    {


        Stock stock;
        FormStatus status = FormStatus.Add;



        public FmEditStockInfo()
        {
            InitializeComponent();
            //stockData = sd;
            stock = new Stock();
        }

        public FmEditStockInfo(Stock s)
            : this()
        {
            //stockData = sd;
            stock = s;

            if (StockData.StockList.Stocks.Contains(s))
            {
                status = FormStatus.Edit;
            }
        }

        private void txtID_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            stock.ID = txtID.Text;
            stock.Name = txtName.Text;
            stock.Desc = txtDesc.Text;
            if (status == FormStatus.Add)
            {
                StockData.StockList.Stocks.Add(stock);
            }

            this.Close();
        }

        private void FmEditStockInfo_Load(object sender, EventArgs e)
        {
            this.txtID.Text = stock.ID;
            this.txtName.Text = stock.Name;
            this.txtDesc.Text = stock.Desc;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }



    }
}